// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

import { VerticalBox } from "../common/layout.slint";
import { Button } from "./button.slint";
import { Palette } from "./std-widgets-impl.slint";
import { StandardButton } from "../common/standardbutton.slint";

import { Date, DatePickerBase } from "../common/datepicker_base.slint";
export { Date }

export component DatePickerPopup inherits PopupWindow  {
    in property <string> title: "Select date";
    in property <Date> date <=> base.date;

    property <brush> state: Palette.color-scheme == ColorScheme.dark ? #ffffff : #000000;
    property <brush> state-secondary: Palette.color-scheme == ColorScheme.dark ? #000000 : #ffffff;

    callback canceled();
    callback accepted(date: Date);

    width: 360px;
    height: 524px;
    close-policy: PopupClosePolicy.no-auto-close;

    background-layer := Rectangle {
        border-radius: 8px;
        background: Palette.control-background;
        width: dialog.width;
        height: dialog.height;
    }

    dialog := Dialog {
        padding: 8px;

        base := DatePickerBase {
            title: root.title;
            style: {
                  border-brush: Palette.border,
                  vertical-spacing: 8px,
                  horizontal-spacing: 4px,
                  calendar-style: {
                      spacing: 8px,
                      delegate-style: {
                          font-size: 14px,
                          font-weight: 500,
                          foreground: Palette.foreground,
                          state-brush: root.state,
                          background-selected: Palette.accent-background,
                          foreground-selected: Palette.accent-foreground,
                          state-brush-selected: root.state-secondary,
                          border-color-today: Palette.accent-background,
                          foreground-today: Palette.accent-background,
                          state-brush-today: root.state,
                      }
                  },
                  icon-button-style: {
                      foreground: Palette.foreground,
                      state-brush: root.state,
                      icon-size: 12px,
                  },
                  current-day-style: {
                      foreground: Palette.foreground,
                      font-weight: 300,
                      font-size: 28px,
                  },
                  title-style: {
                    font-size: 14px,
                    font-weight: 500,
                    foreground: Palette.foreground,
                  },
                  previous-icon: @image-url("./_arrow_back.svg"),
                  next-icon: @image-url("./_arrow_forward.svg"),
                  drop-down-icon: @image-url("./_dropdown.svg"),
                  input-icon: @image-url("./_edit.svg"),
                  calendar-icon: @image-url("./_calendar.svg"),
                  selection-button-style: {
                      foreground: Palette.foreground,
                      state-brush: root.state,
                      icon-size: 8px,
                      font-size: 14px,
                      font-weight: 500
                  }
            };
        }

        StandardButton {
                kind: cancel;

            clicked => {
                root.close();
                root.canceled();
            }
        }

        StandardButton {
            enabled: base.ok-enabled();
            kind: ok;

            clicked => {
                root.close();
                root.accepted(base.get-current-date());
            }
        }
     }
}
